package com.future.mayi.activity;

import android.content.Context;
import android.content.Intent;

import com.future.mayi.model.KefuModels;
import com.future.mayi.model.OldGoodsModel;

public class ServiceActivity extends BaseTitleActivity {

//    @BindView(R.id.tv_online)
//    TextView tvOnline;
//    @BindView(R.id.tv_phone)
//    TextView tvPhone;
//    @BindView(R.id.rl_online)
//    RelativeLayout rlOnline;
//    @BindView(R.id.rl_phone)
//    RelativeLayout rlPhone;


    private KefuModels kefuModels;

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("联系客服");
    }

    public static void startActivity(Context context) {
        startActivity(context, null);
    }

    public static void startActivity(Context context, OldGoodsModel goodsModel) {
        Intent intent = new Intent(context, ServiceActivity.class);
        if (goodsModel != null) {
            KefuModels kefuModels = new KefuModels();
            kefuModels.setTitle(goodsModel.getGoods_title());
            kefuModels.setPrice(String.valueOf(goodsModel.getPrice()));
            kefuModels.setGoodsId(String.valueOf(goodsModel.getGoods_id()));
            kefuModels.setGoodsNumber(goodsModel.getGoods_sn());
            kefuModels.setImg((goodsModel.getList_img() == null || goodsModel.getList_img().size() == 0) ? null : goodsModel.getList_img().get(0));
            intent.putExtra("kefu", kefuModels);
        }
        context.startActivity(intent);
    }

    @Override
    protected void initLayout() {
//        setContentView(R.layout.activity_service);
    }

    @Override
    protected void initView() {
//        float xy = 726.0f / 216.0f;
//        int height = (int) (((float) (CommonUtils.getScreenSize(this)[0] - CommonUtils.dip2px(this, 20))) / xy);
//        rlOnline.getLayoutParams().height = height;
//        rlPhone.getLayoutParams().height = height;

    }

    private String phone;

    @Override
    protected void initDates() {
        if (getIntent() != null && getIntent().getSerializableExtra("kefu") != null)
            kefuModels = (KefuModels) getIntent().getSerializableExtra("kefu");

//        new HttpRequest<DefaultResponse>()
//                .with(this)
//                .setApiCode(ApiCst.getKfrx)
//                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
//                    @Override
//                    public void onSuccess(DefaultResponse response) {
//                        try {
//                            JSONObject object = new JSONObject(response.content);
//                            String content = object.optString("info");
//
//                            ServiceModel serviceModel = App.getGson().fromJson(content, ServiceModel.class);
//                            if (serviceModel == null) return;
//                            phone = serviceModel.getPhone();
//
//                            tvPhone.setText("人工客服（" + serviceModel.getManual_time() + "）\n".concat(phone));
//                            tvOnline.setText("在线客服（" + serviceModel.getOnline_time() + "）");
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//
//                    @Override
//                    public void onFail(String message) {
//                        toast(message);
//                    }
//                })
//                .start(new DefaultResponse());

    }

    @Override
    protected void initListener() {

    }

//    @OnClick({R.id.rl_online, R.id.rl_phone})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.rl_online:
//                KefuUtils.startActivity(this, kefuModels);
//                break;
//            case R.id.rl_phone:
//                if (TextUtils.isEmpty(phone)) {
//                    initDates();
//                    toast("正在获取客服电话");
//                    return;
//                }
//                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
//                break;
//        }
//    }


}
